package yuxi.zy5;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class demo {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ideadashuju12\\liu_ya_kai\\src\\yuxi\\zy5\\book.xml");
        Element root = read.getRootElement();
        List<Element> book = root.elements();
        System.out.println("id大于等于2的所有图书信息");
        for (Element books : book) {
            if (Integer.parseInt(books.attributeValue("id"))>=2){
                System.out.println(books.attributeValue("id"));
                System.out.println(books.elementText("title"));
                System.out.println(books.elementText("publishDate"));
                System.out.println(books.elementText("price"));
            }
        }
        System.out.println("============================");
        System.out.println("书名中包含Java的所有图书信息");
        for (Element books : book) {
            if (books.elementText("title").contains("Java")){
                System.out.println(books.attributeValue("id"));
                System.out.println(books.elementText("title"));
                System.out.println(books.elementText("publishDate"));
                System.out.println(books.elementText("price"));
            }
        }
        System.out.println("============================");
        System.out.println("价格大于50元的所有图书信息");
        for (Element books : book) {
            if (Integer.parseInt(books.elementText("price"))>50){
                System.out.println(books.attributeValue("id"));
                System.out.println(books.elementText("title"));
                System.out.println(books.elementText("publishDate"));
                System.out.println(books.elementText("price"));
            }
        }
    }
}
